<?php
/**
 * Created by PhpStorm.
 * User: D
 * Date: 2018/12/2
 * Time: 18:34
 */

echo '开始时间：' . date('Y-m-d H:i:s') . PHP_EOL;

$workers = [];
$urls = [
    'https://www.baidu.com/',
    'https://www.sina.com.cn/',
    'https://www.qq.com/',
    'https://www.baidu.com?search=imooc',
    'https://www.baidu.com?search=哇哈哈',
    'https://www.baidu.com?search=首发',
];

for ($i=0;$i<6;$i++) {
    $process = new swoole_process(function (swoole_process $process) use ($i, $urls) {
        $content = curlData($urls[$i]);
        echo $content . PHP_EOL;
    }, true);
    $pid = $process->start();
    $workers[$pid] = $process;
}

foreach ($workers as $process) {
    echo $process->read();
}

function curlData($url)
{
    sleep(1);
    return $url . "-----success" . PHP_EOL;
}

echo '结束时间：' . date('Y-m-d H:i:s') . PHP_EOL;